﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SelfService.DataAccess.Migrations
{
    public partial class 更新数据表 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ClientCardType_SysCardType_CardTypeId",
                table: "ClientCardType");

            migrationBuilder.DropForeignKey(
                name: "FK_ClientPayTypes_SysPayType_PayTypeId",
                table: "ClientPayTypes");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysPayType",
                table: "SysPayType");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysCardType",
                table: "SysCardType");

            migrationBuilder.RenameTable(
                name: "SysPayType",
                newName: "SysPayTypes");

            migrationBuilder.RenameTable(
                name: "SysCardType",
                newName: "SysCardTypes");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysPayTypes",
                table: "SysPayTypes",
                column: "ID");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysCardTypes",
                table: "SysCardTypes",
                column: "ID");

            migrationBuilder.CreateTable(
                name: "SysClientsLog",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ClientId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    Info = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Module = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Level = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysClientsLog", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysClientsLog_SysClients_ClientId",
                        column: x => x.ClientId,
                        principalTable: "SysClients",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "SysPatients",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    CardNo = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Name = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Age = table.Column<int>(type: "int", nullable: false),
                    Sex = table.Column<int>(type: "int", nullable: false),
                    Balance = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
                    IdCardNo = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastTime = table.Column<DateTime>(type: "datetime(6)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPatients", x => x.ID);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "SysPatientLoges",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    PatientId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    IdCardNo = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Action = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Amount = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPatientLoges", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysPatientLoges_SysPatients_PatientId",
                        column: x => x.PatientId,
                        principalTable: "SysPatients",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_SysClientsLog_ClientId",
                table: "SysClientsLog",
                column: "ClientId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPatientLoges_PatientId",
                table: "SysPatientLoges",
                column: "PatientId");

            migrationBuilder.AddForeignKey(
                name: "FK_ClientCardType_SysCardTypes_CardTypeId",
                table: "ClientCardType",
                column: "CardTypeId",
                principalTable: "SysCardTypes",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_ClientPayTypes_SysPayTypes_PayTypeId",
                table: "ClientPayTypes",
                column: "PayTypeId",
                principalTable: "SysPayTypes",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ClientCardType_SysCardTypes_CardTypeId",
                table: "ClientCardType");

            migrationBuilder.DropForeignKey(
                name: "FK_ClientPayTypes_SysPayTypes_PayTypeId",
                table: "ClientPayTypes");

            migrationBuilder.DropTable(
                name: "SysClientsLog");

            migrationBuilder.DropTable(
                name: "SysPatientLoges");

            migrationBuilder.DropTable(
                name: "SysPatients");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysPayTypes",
                table: "SysPayTypes");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SysCardTypes",
                table: "SysCardTypes");

            migrationBuilder.RenameTable(
                name: "SysPayTypes",
                newName: "SysPayType");

            migrationBuilder.RenameTable(
                name: "SysCardTypes",
                newName: "SysCardType");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysPayType",
                table: "SysPayType",
                column: "ID");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SysCardType",
                table: "SysCardType",
                column: "ID");

            migrationBuilder.AddForeignKey(
                name: "FK_ClientCardType_SysCardType_CardTypeId",
                table: "ClientCardType",
                column: "CardTypeId",
                principalTable: "SysCardType",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_ClientPayTypes_SysPayType_PayTypeId",
                table: "ClientPayTypes",
                column: "PayTypeId",
                principalTable: "SysPayType",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
